package sample.crawler.base;

import sample.crawler.*;

import java.util.Map;

public class TaskFactory {

    static BaseTask baidu = null;
    static BaseTask gaode = null;
    static BaseTask m360 = null;
    static BaseTask sogou = null;
    static BaseTask tencent = null;

    public static void init(Map<String, Object> urlMap){
        urlMap.keySet().forEach(x->{
            if(x.equals("baidu")) baidu = new BaiduTask(urlMap.get(x).toString());
            if(x.equals("gaode")) gaode = new GaodeTask(urlMap.get(x).toString());
            if(x.equals("360")) m360 = new M360Task(urlMap.get(x).toString());
            if(x.equals("sogou")) sogou = new SogouTask(urlMap.get(x).toString());
            if(x.equals("tencent")) tencent = new TencentTask(urlMap.get(x).toString());
        });
    }

    public static BaseTask getTask(String map){
        switch (map) {
            case "baidu": {
                return baidu;
            }
            case "gaode": {
                return gaode;
            }
            case "360": {
                return m360;
            }
            case "sogou": {
                return sogou;
            }
            case "tencent": {
                return tencent;
            }
        }
        return null;
    }
}
